/*
 *  WsvJdbc - a JDBC driver for WSV (values separated by whatever) data files
 *  Copyright (C) 2004  Daniele Pes
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


package axs.jdbc.utils;


/**
 * 
 * This class is used to provide String utilities for the WsvJdbc driver.
 * 
 * @author 	Daniele Pes  
 * @version    $Id: StringUtilities.java,v 1.2 2007/04/16 17:24:37 montag451 Exp $
 */
public class StringUtilities {

   public static boolean isInStringVector(String[] strVect, 
   													String str){
   	boolean result = false;
   	if (strVect == null)
   		return result;
   	for (int i=0; i<strVect.length; i++){
   		if (strVect[i].equals(str)){
				result = true;
				break;
   		}    			
   	}
   	return result; 
   }


	public static boolean isInString(String strToBeSearchedIn, 
												String strToBeSearchedFor){
		boolean result = false;
		if (strToBeSearchedIn == null)
			return result;		
		int pos = strToBeSearchedIn.indexOf(strToBeSearchedFor);
		if (pos>=0) 
			result = true;				
		return result; 
	}


	public static boolean isNumeric(String s){
		boolean result = false;		
		//
		try {
			Double.parseDouble(s);
			result = true;
		}
		catch (Exception e) {
			; // s is not a number
		}
		return result;
	}


	public static boolean isInteger(String s){
		boolean result = false;		
		//
		try {
			Integer.parseInt(s);
			result = true;
		}
		catch (Exception e) {
			; // s is not an integer
		}
		return result;
	}
	
	
	public static String getUpperCaseWithoutBlanks(String str){
		if(str != null)		
			return str.toUpperCase().replaceAll(" ", "");
		else
			return null;
	}
	
	
	public static String getNewStringReplyingBaseString(String baseStr,
									  								    int    howManyTimes){
		String result;
		//
		result = null;
		if(baseStr != null && howManyTimes>0){
			result = "";
			for (int i = 0; i < howManyTimes; i++) {
				result += baseStr;
			}
		}	
		return result;
	}

	public static String getClassName(Class c) {
	   return StringUtilities.getClassName(c.getName());
	}

	/**
	 * Get the class name given the fully qualified class name.
	 */
	public static String getClassName(String fqnName) {
	   int pos = 0;
	   pos = fqnName.lastIndexOf('.');
	   if (pos == -1)
	      return fqnName;
	   String name = fqnName.substring(pos + 1);
	   return name;
	}
	
	
	public static boolean isEmpty(String s){
		return (s == null || s.equals(""));
	}
	
	
	public static boolean isEmptyIgnoreBlanks(String s){
		return (s == null || s.replaceAll(" ", "").equals(""));
	}
}
